import React, {useCallback, useEffect} from 'react';
import {
  Button,
  NativeModules,
  PermissionsAndroid,
  Text,
  View,
} from 'react-native';

export const RNAliyun = NativeModules.RNAliyun;

export default () => {
  const handleGetPermission = useCallback(async () => {
    await PermissionsAndroid.requestMultiple([
      'android.permission.CAMERA',
      'android.permission.READ_PHONE_STATE',
      'android.permission.WRITE_EXTERNAL_STORAGE',
      'android.permission.READ_EXTERNAL_STORAGE',
    ]);
  }, []);

  const handleInitSdk = useCallback(() => {
    RNAliyun.init();
  }, []);

  const handleGetMetaInfo = useCallback(() => {
    RNAliyun.getMetaInfo();
  }, []);

  const handleGetCertifyId = useCallback(() => {
    RNAliyun.getCertifyId();
  }, []);

  const handleFaceVerify = useCallback(() => {
    RNAliyun.faceVerify('311deed69ac112b3964448776a0a6b77');
  }, []);

  return (
    <View>
      <Text>1. 获取权限</Text>
      <Button title="获取权限" onPress={handleGetPermission} />
      <Text>2. 初始化sdk</Text>
      <Button title="初始化sdk" onPress={handleInitSdk} />
      <Text>3. 获取设备信息</Text>
      <Button title="获取设备信息" onPress={handleGetMetaInfo} />
      <Text>4. 获取id</Text>
      <Button title="获取id" onPress={handleGetCertifyId} />
      <Text>5. 发起实人认证</Text>
      <Button title="发起实人认证" onPress={handleFaceVerify} />
    </View>
  );
};
